package com.ohuang.wallpapermanager.util

import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date

object TimeUtil {

    /**
     * 根据时间戳获取周几
     * 0-为周日
     * 1-星期一
     * 后面以此类推
     */
    fun getWeek(time: Long): Int {
        val calendar = Calendar.getInstance()
        calendar.timeInMillis = time
        return calendar.get(Calendar.DAY_OF_WEEK)-1
    }

    /**
     * 获取小时
     */
    fun getHour(time: Long): Int {
        val calendar = Calendar.getInstance()
        calendar.timeInMillis = time
        return calendar.get(Calendar.HOUR_OF_DAY)
    }

    /**
     * 获取分钟
     */
    fun getMinute(time: Long): Int {
        val calendar = Calendar.getInstance()
        calendar.timeInMillis = time
        return calendar.get(Calendar.MINUTE)
    }

    fun getTime(time: Long): String {
        val date = Date(time)
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        return sdf.format(date)
    }

    fun getSimpleTime(time: Long): String {
        val date = Date(time)
        val sdf = SimpleDateFormat("MM-dd HH:mm")
        return sdf.format(date)
    }
}